<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2016/5/29
  Time: 9:35
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <link rel="stylesheet" href="/wechat/home/turnbig.css">
    <jsp:include page="../public/head.jsp" flush="true" />
</head>
<body style="background:url(/wechat/images/bg1.jpg) 50% 50% no-repeat;">
<jsp:include page="../public/header.jsp" flush="true" />
<form id="week" action="/home/shopCar.do" method="post"  >
    <input type="hidden" name="order" id="order">
    <input  name="totalCount" type="hidden" id="totalCount">
    <input  name="totalPrice" type="hidden" id="totalPrice">
</form>
<input type="hidden" name="date" value="${rdate}"  >
<form id="form" >
    <input type="hidden" value="${product.price}" name="goodPrcie" id="goodPrcie" />
    <input type="hidden" value="${product.id}" name="goodId" />
    <input type="hidden" value="${product.image}" name="goodNormalImage" />
    <input type="hidden" value="${product.name}" name="goodName" />
    <input type="hidden" value="${productClassId}" name="productClassId" />
    <input type="hidden" value="0" name="goodAccount" id="count" />
</form>
<div class="my_turnbig">
<section>

    <!-- 区域列表 -->
    <div class="cont">
        <c:choose>
            <c:when test="${empty backBt}">
                <div class="quit" onclick="history.go(-1)"><i class="iconfont icon-shouye">&#xe627;</i></div>
            </c:when>
            <c:otherwise>
                <div class="quit" onclick="return window.location.replace('${backBt}')"><i class="iconfont icon-shouye">&#xe627;</i></div>
            </c:otherwise>
        </c:choose>
        <img src="${product.bigImage}">
        <div class="wrap">
            <a href="/home/beforelogin/productComment.do?id=${product.id}"><span class="s1">评价</span></a>
            <div class="info">
                <div class="mask"></div>
                <div class="add _add">
                    <div class="left" onclick="countSub()"></div>
                    <span class="center" id="scount">0</span>
                    <div class="right" onclick="countAdd()"></div>
                </div>
            </div>
            <span class="s3" onclick="buy()">购买</span>
        </div>
        </div>
</section>
</div>
<input type="hidden" id="total" value="0">
    <%--<div>${product.name}</div>--%>
<script>
    function countAdd() {
        var current = $('#count').val();
//        var currentCount = $("#count").val();
        var currenttotal = $("#total").val();
        var price = $('#goodPrcie').val();
        current++;
        currenttotal = (parseFloat(price)+parseFloat(currenttotal)).toFixed(1);
        $("#count").val(current);
        $("#total").val(currenttotal);
        $("#scount").text(current) ;
    }

    function countSub(id) {
        var current = $('#count').val();
//        var currentCount = $("#count").val();
        var currenttotal = $("#total").val();
        var price = $('#goodPrcie').val();
        if (current == 0){
            return;
        }
        current--;
//        currentCount++;
        currenttotal = (parseFloat(currenttotal)-parseFloat(price)).toFixed(1);
        $("#count").val(current);
        $("#total").val(currenttotal);
        $("#scount").text(current) ;
    }

    function buy(){
        var form = $("#form");
        var goods = [];
//        var tmp = $("#week").serializeObject();
        var key = $("input[name='date']").val();
        var temp = form.serializeObject();
        if (temp.goodAccount > 0) {
            temp.shopId = key;
            goods.push(temp);
        }
//        console.log(JSON.stringify(goods));
        if (goods.length > 0) {
            var data = '{"' + key + '":' + JSON.stringify(goods) + '}';
//            console.log(data);
            $("#order").val(data);
            $("#totalCount").val($("#count").val());
            $("#totalPrice").val($("#total").val());
//            console.log($("#week").serialize());
//            window.location.href = "/home/shopCar.do?"+$("#week").serialize();
            $("#week").submit();
        }
    }

    $.fn.serializeObject = function()
    {
        var o = {};
        var a = this.serializeArray();
        $.each(a, function() {
            if (o[this.name]) {
                if (!o[this.name].push) {
                    o[this.name] = [o[this.name]];
                }
                o[this.name].push(this.value || '');
            } else {
                o[this.name] = this.value || '';
            }
        });
        return o;
    };
</script>
</body>
</html>
